import request from '@/utils/request'

/**
 * 获取基础题库
 * @returns 基础题库列表
 */
export const getDatabaseListAPI = (searchInfo) => {
  return request({
    url: '/questions',
    params: searchInfo
  })
}

/**
 * 删除试题
 * @param {Object} delData 试题信息
 * @returns 删除结果
 */
export const delQuestionAPI = (delData) => {
  return request({
    url: `/questions/${delData.id}`,
    method: 'DELETE'
  })
}

/**
 * 试题精选
 * @param {String} id 试题id
 * @param {*} choiceState 试题精选状态
 * @returns 精选结果
 */
export const featureQuestionAPI = (id, choiceState) => {
  return request({
    url: `/questions/choice/${id}/${choiceState}`,
    method: 'PATCH'
  })
}

/**
 * 添加试题
 * @param {Object} formData 试题数据
 * @returns 添加结果
 */
export const addQuestionAPI = (formData) => {
  return request({
    url: '/questions',
    data: formData,
    method: 'POST'
  })
}

/**
 * 获取试题详情
 * @param {String} quesId 试题id
 * @returns 试题详情
 */
export const getQuestionInfoAPI = (quesId) => {
  return request({
    url: `/questions/${quesId}`
  })
}

/**
 * 修改试题
 * @param {Object} editForm 试题信息
 * @returns 修改结果
 */
export const editQuestionAPI = (editForm) => {
  return request({
    url: `/questions/${editForm.id}`,
    data: editForm,
    method: 'PUT'
  })
}
